var listPage = avalon.define({
	$id: "listPage",
	noData: "",
	products: []
});

mui.ready(function() {
	var mui_products = mui('#productList');
	var pageNo = 0;
	mui.init({
		gestureConfig: {
			tap: true, //默认为true 
			doubletap: true, //默认为false 
			longtap: true
		},
		pullRefresh: {
			container: "#productList",
			up: {
				height: 10,
				auto: true,
				contentrefresh: $.i18n.contentRefresh,
				contentnomore: $.i18n.noData,
				callback: function() {
					listPage.noData="";
					setTimeout(function() {
						pageNo=pageNo+1;
						mui.ajax('/product/new.json', {
							data: {
								pageNo: pageNo
							},
							dataType: 'json',
							success: function(data) {
								var products=listPage.products;
								var items=data;
								avalon.each(items, function(i, item) {
									products.push(item);
								});
								listPage.products=products;
								mui_products.pullRefresh().endPullupToRefresh(false);
								
								if(listPage.products.length==0){
									listPage.noData="<img src='../../resources/images/noDataImg.png'><p>No data</p>";
								}
								
							}
						});
					}, window.DAHUA_CONFIG.LOADING_TIME);
	
				}
			}
		}
	});
	
	mui(".mui-table-view").on('tap', 'a', function() {
		var url = this.getAttribute('href');
		var id = this.getAttribute('data-id');
		mui.openWindow({
			url: url+"?id="+id
		});
	});
	 

});